/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.games.epkb.entityClasses;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author plebani
 */
@Entity
@Table(name = "antecedent")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Antecedent.findAll", query = "SELECT a FROM Antecedent a"),
    @NamedQuery(name = "Antecedent.findByIdRule", query = "SELECT a FROM Antecedent a WHERE a.antecedentPK.idRule = :idRule"),
    @NamedQuery(name = "Antecedent.findByIdGPIKPI", query = "SELECT a FROM Antecedent a WHERE a.antecedentPK.idGPIKPI = :idGPIKPI"),
    @NamedQuery(name = "Antecedent.findByThreshold", query = "SELECT a FROM Antecedent a WHERE a.threshold = :threshold")})
public class Antecedent implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected AntecedentPK antecedentPK;
    @Column(name = "Threshold")
    private String threshold;
    @JoinColumn(name = "Id_GPI_KPI", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private GpiKpi gpiKpi;
    @JoinColumn(name = "Id_Rule", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private AssociationRule associationRule;

    public Antecedent() {
    }

    public Antecedent(AntecedentPK antecedentPK) {
        this.antecedentPK = antecedentPK;
    }

    public Antecedent(String idRule, String idGPIKPI) {
        this.antecedentPK = new AntecedentPK(idRule, idGPIKPI);
    }

    public AntecedentPK getAntecedentPK() {
        return antecedentPK;
    }

    public void setAntecedentPK(AntecedentPK antecedentPK) {
        this.antecedentPK = antecedentPK;
    }

    public String getThreshold() {
        return threshold;
    }

    public void setThreshold(String threshold) {
        this.threshold = threshold;
    }

    public GpiKpi getGpiKpi() {
        return gpiKpi;
    }

    public void setGpiKpi(GpiKpi gpiKpi) {
        this.gpiKpi = gpiKpi;
    }

    public AssociationRule getAssociationRule() {
        return associationRule;
    }

    public void setAssociationRule(AssociationRule associationRule) {
        this.associationRule = associationRule;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (antecedentPK != null ? antecedentPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Antecedent)) {
            return false;
        }
        Antecedent other = (Antecedent) object;
        if ((this.antecedentPK == null && other.antecedentPK != null) || (this.antecedentPK != null && !this.antecedentPK.equals(other.antecedentPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.games.epkb.entityClasses.Antecedent[ antecedentPK=" + antecedentPK + " ]";
    }
    
}
